$(document).ready(function () {
	sbqd.onload();
})

var sbqd = (function () {

	var init = function () {}

	return {
		onload: function () {
			init();
			sbqd.sbqdList();
			sbqd.onClickSbBtn();
			sbqd.onClickSbEdit();
		},
		sbqdList: function () {
			var data = [{
					"id": "10101",
					"name": "增值税申报（一般纳税人使用）",
					"url":"bsdt/sbqd/sblc1.html",
					"dataStart": "2019-10-12",
					"dataEnd": "2019-10-12",
					"status": "已申报",
					"formlist": [{
							"url": 'sblc_bb.html',
							"number": "001",
							"name": "增值税纳税申报表附列资料（一）2017版",
							"type": "月",
							"status": "已填写",
							"date": "2018-05-01",
							"operation": null
						},
						{
							"url": 'sb2.html',
							"number": "002",
							"name": "增值税纳税申报表附列资料（二）2017版",
							"type": "月",
							"status": "已填写",
							"date": "2018-05-01",
							"operation": null
						}

					]
				},
				{
					"id": "10102",
					"name": "附加税（费）申报",
					"url":"bsdt/sbqd/sblc2.html",
					"dataStart": "2019-10-12",
					"dataEnd": "2019-10-12",
					"status": "已申报",
					"formlist": [{
							"url": "sb3.html",
							"number": "001",
							"name": "增值税纳税申报表附列资料（三）2017版",
							"type": "月",
							"status": "已填写",
							"date": "2018-05-01",
							"operation": null
						},
						{
							"url": "sb4.html",
							"number": "002",
							"name": "增值税纳税申报表附列资料（四）2017版",
							"type": "月",
							"status": "已填写",
							"date": "2018-05-01",
							"operation": null
						}

					]
				}
			]
			window.parent.dataSb=data;
			window.data = data;
			
			for (i = 0; i < data.length; i++) {
				var html = '<div class="wxl_m_sbqd_list">' +
					'<p class="f_14 clearfix">' +
					'<span class="wxl_radio"><i class="iconfont icon-radiobox"></i></span>' +
					'<span class="wxl_list_two">' + data[i].name + '</span>' +
					'<span class="wxl_skssq">税款所属期：' + data[i].dataStart + '至' + data[i].dataEnd + '</span>' +
					'<span class="wxl_sb_state">' + data[i].status + '</span>' +
					'<span class="wxl_btn"><label class="button wxl_bg_blue1 wep_cursor" data-id="'+data[i].id+'">立即申报</label></span>' +
					'</p>' +
					'<div class="wxl_table_box wxl_bg_fff" style="display: none;">' +
					'<table cellpadding="0" cellspacing="0" width="100%" border="0" class="display" id="example' + data[i].id + '">' +
					'<thead>' +
					' <tr>' +
					' <th>编号</th>' +
					'<th>申报表名称</th>' +
					'<th>类型</th>' +
					'<th>状态</th>' +
					'<th>填表日期</th>' +
					'<th>操作</th>' +
					'</tr>' +
					'</thead>' +
					'<tbody data-name="'+data[i].name+'" data-id="'+data[i].id+'" data-url="'+data[i].url+'">' +
					' </tbody>' +
					'</table>' +
					'</div>' +
					'</div>';
				$(".wxl_g_sbqd_con").append(html);
				$('#example' + data[i].id).dataTable({
					"data": data[i].formlist,
					"columnDefs": [{
						// targets用于指定操作的列，从第0列开始，-1为最后一列，这里第六列
						// return后边是我们希望在指定列填入的按钮代码
						"targets": -1,
						"render": function (data, type, full, meta) {
							return '<i class="iconfont icon-xiugai" style="color:#13b060"></i><span data-id="'+ i +'" data-number="'+full.number+'" data-url="'+full.url+'" class="wep_table_xg" style="margin-left:10px">修改</span>';
						}
					}],

					"columns": [{
							"data": "number"
						},
						{
							"data": "name"
						},
						{
							"data": "type"
						},
						{
							"data": "status"
						},
						{
							"data": "date"
						},
						{
							"data": "operation"
						}
					],
					"paging": false,
					"info": false,
					"lengthChange": false,
					"searching": false
				});

			}
		},
		//弹出显示
		onShow: function () {
			curSeg.onload();
		},
		//封装申报流程页面跳转
		jumpIframe:function(nowNumber,nowIframeUrl,nowHtml,nowId,nowUrl){
			window.parent.tableNumber=nowNumber;
			window.parent.tableId=nowId;
			
			$("#sidebar",parent.document).addClass("menu-min");
			var slider_w=$("#sidebar",parent.document).outerWidth();
			var window_w=$("body",parent.document).outerWidth();
			var content_w=window_w-slider_w-2+"px";
   		     $(".content-wrapper",parent.document).css("width",content_w)
   		   
			var as=$(".page-tabs-content a",parent.document);
        	var $likeA="";//路径一样的a
        	for(var i=0;i<as.length;i++){
        		var aUrl=$(as[i]).data("url");
        		if(nowUrl==aUrl){
        			$likeA=$(as[i]);
        		}
        	}
        	if($likeA){     //路径一样
        		var currentId = $likeA.data('id');
		        if (!$likeA.hasClass('active')) {
		            $('.mainContent .LRADMS_iframe',parent.document).each(function () {
		                if ($(this).data('id') == currentId) {
		                    $(this).show().siblings('.LRADMS_iframe').hide();
		                    return false;
		                }
		            });
		            $likeA.addClass('active').siblings('.menuTab').removeClass('active');
		            $("#iframe"+nowId,parent.document).attr("src",nowUrl);
               	}
        	}else{         //路径不一样
        		$(as).removeClass("active");
				var html='<a href="javascript:;" class="active menuTab" data-id="' + nowId + '" data-url="' + nowUrl + '"><label class="nav_text">' + nowHtml + '</label><span class="btn_close"><i class="icon iconfont icon-guanbi1"></i></span></a>';
				$(".page-tabs-content",parent.document).append(html);
				var str1 = '<iframe class="LRADMS_iframe" id="iframe' + nowId + '" name="iframe' + nowId + '"  width="100%" height="100%" src="' + nowUrl + '" frameborder="0" data-id="' + nowId + '" data-url="' + nowUrl + '" seamless></iframe>'; 
	            $(".mainContent",parent.document).find('iframe.LRADMS_iframe').hide();  
	            $(".mainContent",parent.document).append(str1);		            
	        }
        	$("#iframe"+nowId,parent.document).contents().find("#sblc_bg_iframe").attr("src",nowIframeUrl);
		},
		//封装拼接左侧列表项
		pjLi:function(nowId,nowNumber){
			var html='';
			for(var i=0;i<data.length;i++){
				if(data[i].id==nowId){
					var formList=data[i].formlist;
					for(var j=0;j<formList.length;j++){
						if(j+1<nowNumber){
							html+='<li>'+
								'<a title="'+formList[j].name+'">'+
									'<span>√</span>'+
									'<h1 data-tableId="'+nowId+'" data-tableNumber="'+formList[j].number+'">'+formList[j].name+'</h1>'+
								'</a>'+
							'</li>'
						}else{
							html+='<li>'+
								'<a title="'+formList[j].name+'">'+
									'<span>'+(j+1)+'</span>'+
									'<h1 data-tableId="'+nowId+'" data-tableNumber="'+formList[j].number+'">'+formList[j].name+'</h1>'+
								'</a>'+
							'</li>'
						}
						
					}
					
				}
			}
			$("#iframe"+nowId,parent.document).contents().find("#sblc_iframes ul").html(html);
		},
		//点击立即申报
		onClickSbBtn: function () {
			$('.wxl_g_sbqd .button').on("click", function (e) {
				var $this=$(e.target);
				var nowNumber=1;
				for(var i=0;i<data.length;i++){
					if(data[i].id==$this.data("id")){
						var nowIframeUrl=data[i].formlist[0].url;
						var nowHtml=data[i].name;
						var nowId=$this.data("id");
						var nowUrl=data[i].url;
					}
				}
				sbqd.jumpIframe(nowNumber,nowIframeUrl,nowHtml,nowId,nowUrl);
				sbqd.pjLi(nowId,1);
			})
		},
		//点击修改
		onClickSbEdit:function () {
			$(".wep_table_xg").on('click',function(e){
	
				var $this=$(e.target);
				var nowNumber=$this.data("number");
				var nowIframeUrl=$this.data("url");
				var nowHtml=$this.parent().parent().parent().data("name");
				var nowId=$this.parent().parent().parent().data("id");
				var nowUrl=$this.parent().parent().parent().data("url");
				sbqd.jumpIframe(nowNumber,nowIframeUrl,nowHtml,nowId,nowUrl);				
				sbqd.pjLi(nowId,nowNumber);	
			})
		}
	}
})();